@extends('manage._layout')
@section('page-title')
    修改-{{$menuName}}-模块
@stop
@section('page-breadcrumbs')
    <li>
        <a href="{{route('menu_list')}}" title="">
            菜单管理
        </a>
    </li>
    <li class="current">
        <a href="javascript:;" title="">
            {{$menuName}}模块修改
        </a>
    </li>
@stop
@section('page-buttons')
    <li>
        <a href="{{route('menu_list')}}" title="">
            <i class="icon-reply"></i>
            <span>返回</span>
        </a>
    </li>
@stop

@section('page-content')
    <form class="form-horizontal" role="form" action="" enctype="multipart/form-data">
        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">模块名称</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" name="name" id="name"
                    value="{{$data->module_name}}"   placeholder="请输入模块名称"><span style="color: red;">菜单的操作模块名称 </span>
            </div>
        </div>

        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">方法名</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" name="action" id="action"
                       value="{{$data->action}}"   placeholder="请输入模块方法名"><span style="color: red;">对应控制器方法名</span>
            </div>
        </div>

        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">权限值</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" name="value" id="value"
                       value="{{$data->value}}"     placeholder="请输入权限值"><span style="color: red;">请按2的次幂填写(如查看1，增加2，修改4，删除8等等,不要填写已存在的权限值)</span>
            </div>
        </div>


        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-default" id="sub">修改</button>
            </div>
        </div>

        <input type="hidden" value="{{$data->id}}" id="module_id"/>
        <input type="hidden" value="{{$data->menu_id}}" id="menu_id"/>

    </form>
    <script>
        $(document).ready(function () {
            $('#sub').click(function () {
                var module_id=$('#module_id').val();
                var menu_id=$('#menu_id').val();
                var module_name=$('#name').val();
                var value=$('#value').val();
                var action=$('#action').val();

                if(module_name==''){
                    layer.alert('请填写模块名称');
                    return false;
                }

                if(value==''){
                    layer.alert('请填写权限值');
                    return false;
                }

                if(action==''){
                    layer.alert('请填写方法名');
                    return false;
                }


                var postdata = {
                    id: module_id,
                    moduleName:module_name,
                    value:value,
                    action:action,
                    menuId:menu_id
                };
                $.ajax({
                    type: 'POST',
                    url: '{{URL::route('menu_module_edit_post')}}',
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                    data: postdata,
                    success: function (res) {
                        if (res.error == 0) {
                            location.href = '{{URL::route('menu_module_list',['id'=>$data->menu_id])}}';
                        } else {
                            layer.alert(res.message);
                        }
                    },
                    error: function(XMLHttpRequest) {
                        if(XMLHttpRequest.status==403){
                            layer.alert(noAccessMsg);
                        }else{
                            layer.alert(otherErrorMsg);
                        }
                    }
                });
            });
            //////////////////////////


        });
    </script>
@stop